<!DOCTYPE html>
<html lang="zh" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('计划列表')"/>
    <th:block th:include="include :: select2-css"/>
    <style>
        .fixed-table-toolbar {
            display: none;
        }
    </style>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">

                    <li>
                        <input name="orderId" type="hidden"/>
                    </li>
                    <li>
                        <input id="status" name="status" type="hidden" value="2,3">
                    </li>
                    <li>
                        <input id="planType" name="planType" type="hidden" value="2">
                    </li>
                    <li>
                        作物名称：
                        <select name="cropNameCn">
                            <option value="" selected="selected">无</option>
                            <option th:each="cropNameCn:${cropNameCns}" th:text="${cropNameCn.cropNameCn}"
                                    th:value="${cropNameCn.cropNameCn}"></option>
                        </select>
                    </li>
                    <li>
                        作物品种：
                        <select name="cropVarieties">
                            <option value="" selected="selected">无</option>
                            <option th:each="ncCai:${ncCais}" th:text="${ncCai.caiName}"
                                    th:value="${ncCai.caiId}"></option>
                        </select>
                    </li>
                    <li class="select-time">
                        <label>播种/定植： </label>
                        <input class="time-input" id="beginTime" name="params[beginTime]" placeholder="开始时间"
                               type="text"/>
                        <span>-</span>
                        <input class="time-input" id="endTime" name="params[endTime]" placeholder="结束时间"
                               type="text"/>
                    </li>
                    <li>
                        生产班组：
                        <select  name="team">
                            <option value="" selected="selected">无</option>
                            <option th:each="cropNameCn:${cropNameCns}" th:text="${cropNameCn.deptName}"
                                    th:value="${cropNameCn.team}"></option>
                        </select>
                    </li>

                    <li>
                        计划制定人：<select name="createBy">
                        <option value="" selected="selected">无</option>
                        <option th:each="user:${users}" th:text="${user.loginName}"
                                th:value="${user.loginName}"></option>
                    </select>
                    </li>


                    <li>
                        <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                class="fa fa-search"></i>&nbsp;搜索</a>
                        <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                class="fa fa-refresh"></i>&nbsp;重置</a>
                    </li>
                </div>
            </form>
        </div>

        <!--<div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:ncPlan:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="system:ncPlan:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:ncPlan:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:ncPlan:export">
                <i class="fa fa-download"></i> 导出
            </a>
        </div>-->
        <div class="col-sm-12 select-table table-striped">
            <table data-mobile-responsive="true" id="bootstrap-table"></table>
        </div>
    </div>
    <div class="bottom-btns"></div>
</div>
<div th:include="include :: footer"></div>
<th:block th:include="include :: select2-js"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:ncPlan:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:ncPlan:remove')}]];
    var prefix = ctx + "system/ncPlan2";

    var landType = [[${@dict.getType('landType')}]];
    $(function () {
        var options = {
            url: prefix + "/sumProductionPlan?planType=2&status=2,3&orderId="+(![[${orderId}]]?0:[[${orderId}]]),
            showFooter: true,
            modalName: "计划",
            showExport: true,
            columns: [
                {
                    title: '序号',
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    },
                    footerFormatter: function () {
                        return "合计";
                    }
                },
                {
                    field: 'deptName',
                    title: '班组',
                    visible: true,
                    footerFormatter: function () {
                        return "--";
                    }
                },
                {
                    field: 'cropNameCn',
                    title: '作物名称',
                    sortable: true,
                    footerFormatter: function () {
                        return "--";
                    }
                },

                {
                    field: 'chaci',
                    title: '茬口',
                    sortable: true,
                    footerFormatter: function (rows) {
                        var sum = 0;
                        for (var i = 0; i < rows.length; i++) {
                            sum += rows[i].chaci
                        }
                        return sum;
                    }
                },

                {
                    field: 'sumArea',
                    title: '面积(亩)',
                    sortable: true,
                    footerFormatter: function (rows) {
                        var sum = 0;
                        for (var i = 0; i < rows.length; i++) {
                            sum += rows[i].sumArea
                        }
                        return sum;
                    }
                },
                {
                    field: 'realAmout',
                    title: '产量(kg)',
                    visible: true,
                    footerFormatter: function (rows) {
                        var sum = 0;
                        for (var i = 0; i < rows.length; i++) {
                            sum += rows[i].realAmout
                        }
                        return sum;
                    }
                }
            ],
            onPostBody: function () {
                //合并页脚
                merge_footer();
            }
        };
        $.table.init(options);
    });

    //合并页脚
    function merge_footer() {
        //获取table表中footer 并获取到这一行的所有列
        var footer_tbody = $('.fixed-table-footer table tbody');
        var footer_tr = footer_tbody.find('>tr');
        var footer_td = footer_tr.find('>td');
        var footer_td_1 = footer_td.eq(0);
        //由于我们这里做统计只需要两列，故可以将除第一列与最后一列的列全部隐藏，然后再设置第一列跨列
        //遍历隐藏中间的列 下标从1开始
        for (var i = 1; i < footer_td.length - 1; i++) {
            footer_td.eq(i).hide();
        }
        //设置跨列
        footer_td_1.attr('colspan', footer_td.length - 1).show();
        //这里可以根据自己的表格来设置列的宽度 使对齐
        footer_td_1.attr('width', "910px").show();
    }

    setTitle("生产计划汇总表",false)
</script>
</body>
</html>